const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const common = require('./webpack.common.js') //公共配置
const { merge } = require('webpack-merge')
const path = require('path')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const OptimizeCssAssetsWebpackPlugin = require('optimize-css-assets-webpack-plugin')
module.exports = merge(common, {
  mode: 'production',
  output: {
    filename: '[name]-[contenthash].bundle.js',
  },
  devtool: false,
  optimization: {
    usedExports: true,
    minimize: true,
    minimizer: [new OptimizeCssAssetsWebpackPlugin()],
  },
  plugins: [
    new CleanWebpackPlugin(),
    new CopyWebpackPlugin({
      patterns: [
        {
          from: path.resolve(__dirname, './src/assets'),
          to: 'assets',
          transformPath(targetPath, absolutePath) {
            return targetPath.replace('public', '')
          },
        },
      ],
    }),
  ],
})
